Embodiments of the present invention are concerned with providing a computer-implemented method, a computer program product and a computer system that facilitate message queue management.
An electronic message refers to any type of data structure exchanged between two parties (e.g., two hardware parties, two software parties, a hardware and software party, etc.) via an electronic communication. The electronic message includes, but is not limited to, an e-mail, an instant message, an audio message, a text message and a facsimile message. In the following, such an electronic message will be simply referred to as a message. The parties involved in the communication of such messages may be referred to as publishers and consumers, with the publisher being a computer device or application running thereon producing such a message and a consumer being a computer device or application running thereon consuming such a message.
Message consumption by a consumer may require the consumer to process the message, for example when the publisher requires a response to the message. This for instance may be the case if the message contains a request for a service or the like in which case the consumer may be the provider of the service or the like. In an environment where a consumer may receive a large number of messages, an intermediary such as a message queue manager may be used to distribute messages received from a number of publishers across a number of consumers in order to ensure that the messages are processed in a timely fashion.
Many implementations of such intermediaries and consumers exist. A non-limiting example of such an implementation is the Java® Message Service (JMS). One of key elements of Java Message Service (JMS) is message-driven beans (MDBs). The JMS is a messaging standard that allows applications based on Java® software technology to create, send, receive and read electronic messages. The JMS enables distributed, loosely coupled, reliable and asynchronous communication between an electronic message publisher (i.e., a computing device generating an electronic message) and an electronic message subscriber (i.e., a computing device receiving the electronic message). MDBs are a component that allows Java® applications to process electronic messages asynchronously. MDBs act as a JMS message listener, which is similar to an event listener/detector except it receives electronic messages instead of events. MDBs monitor a queue receiving electronic messages. When an electronic message arrives at the queue, an instance of the MDB is invoked asynchronously to process the electronic message. The MDB instance may refer to one or more threads executing the MDB.
As explained above, it is possible to have multiple instances of a consumer processing electronic messages concurrently. Such instances may be embodied within a single server or may be distributed across different geographical locations for redundancy reasons, e.g. in order to mitigate the risk of delays to the processing of messages from the queue caused by one or more of the instances (consumers) being unable to successfully process a message, for example because the instance or consumer requires access to a remote resource such as a database that is temporarily unavailable, for example because of remote resource maintenance, the remote resource being down or a network connection to the remote resource being temporarily unavailable.
It is difficult to avoid messages being returned, i.e. rolled back, to the message queue by a consumer incapable of successfully processing the message, as the consumer may be simply unable for reasons beyond its control to successfully process the message as explained above. In such a scenario, the intermediary acting as queue manager simply redistributes the message to one of the consumers. However, if the message or other messages are redistributed to the consumer that returned the unsuccessfully processed message to the message queue, an accumulation of messages that have been unsuccessfully processed by a consumer may occur in the message queue. This can have a negative impact on message throughput for the message queue.